package qingke.me.jdbc;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JdbcConn {
	public static void main(String[] args) {
		Connection conn=null;
		try {
	//		Class.forName("com.masql.jdbc.Drivel");
			String driver = getProperty("db.driver");
			Class.forName(driver);
	//		String url = "jdbc:mysql://localhost:3306/qingke";
			String url = getProperty("db.url");
			String u = getProperty("db.username");
			String p = getProperty("db.password");
			conn = DriverManager.getConnection(url, u, p);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
}
	
	private static String getProperty(String key){
		Properties props = new Properties();
		
		try {
			props.load(new FileInputStream("jdbc.properties"));
			return props.getProperty(key);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return"";
	}
}
